package com.myapi.ModelPoker;

import java.util.ArrayList;

import com.myapi.client.DAO.PlayerDAO;
import com.myapi.server.PokerServiceImpl;

/**
 * Cash Game
 * @author Realease by Yoan Olivier 
 *
 */
public class CashGame extends PokerGame {

	private Dealer cashDealer;
	private ArrayList<Player> players;
	private static final double Cave=100.00;
	private Table table;
	private PokerStyleFactory factory ;
	private PokerServiceImpl pokerServerControler;

	protected CashGame() {
		players=new ArrayList<Player>();
		setBigBlind(0.20);
		setSmallBlind(0.10);
		setAnte(0);
	}

	public boolean addPlayer(String name,String id,double cash){

		if(players.size()==0){
			factory = getPokerStyleFactory();
			table = factory.createTable("CashTable1");
			cashDealer = factory.createDealer("CashDealer1");
			cashDealer.setTable(table);
			table.setDealer(cashDealer);
			pokerServerControler = PokerServiceImpl.getpokerServerControler();
			pokerServerControler.setTable(table);
			Player player = factory.createPlayer(name,id,cash);
			PlayerHand pHand = player.getPlayerHand();
			table.addPlayerHand(pHand);
			pokerServerControler.setPlayers(table.getPlayers());
			players.add(player);

			return true;
		}
		if(players.size()<Table.MAX_PLAYERS){
			Player player = factory.createPlayer(name,id,cash);
			PlayerHand pHand = player.getPlayerHand();
			table.addPlayerHand(pHand);
			pokerServerControler.setPlayers(table.getPlayers());
			players.add(player);
			return true;
		}

		return false;

	}
	public boolean removePlayer(String id){
		for(int i=0;i<players.size();i++){
			if(players.get(i).getId()==id){
				players.remove(i);
				return true;
			}
		}
		return false;
	}



	public void startGame() {
		Table.MAX_PLAYERS=players.size();
		cashDealer.startHand(getAnte(), getSmallBlind(), getBigBlind());
		table.gameRunning=true;
	}

}
